package com.actions.bluetoothbox2.util;

import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.drawable.Drawable;
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;

/**
 * Created by liuyong on 2018/1/3.
 */

public class RoundCornerDrawable extends Drawable {
    final int color;
    final Paint paint;
    int circleRadius;
    int height;
    int width;

    public RoundCornerDrawable(int color, int circleRadius, int height, int width) {
        this.color = color;
        this.circleRadius = circleRadius;
        this.height = height;
        this.width = width;
        int red = (color & 0xff0000) >> 16;
        int green = (color & 0x00ff00) >> 8;
        int blue = (color & 0x0000ff);
        // 实心的画笔
        this.paint = new Paint();
        paint.setStyle(Paint.Style.FILL);
        paint.setAntiAlias(true);
        paint.setAlpha(255);
//        paint.setColor(color);
        Log.i("TAG", "--red==" + red + "--green==" + green + "-blue==" + blue);
        paint.setARGB(255, red, green, blue);

    }

    @Override
    public void draw(@NonNull Canvas canvas) {
        int verticalCenter = height / 2;
        int horizontalCenter = width / 2;

        canvas.drawCircle(horizontalCenter, verticalCenter, circleRadius, paint);
    }

    @Override
    public void setAlpha(@IntRange(from = 0, to = 255) int alpha) {
        paint.setAlpha(alpha);
    }

    @Override
    public void setColorFilter(@Nullable ColorFilter cf) {
        paint.setColorFilter(cf);
    }

    @Override
    public int getOpacity() {
        return PixelFormat.TRANSLUCENT;
    }
}
